package o;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.gamebox.plugin.gameservice.bean.GetGameNoticeResp;
import com.huawei.gamebox.plugin.gameservice.view.GameServiceShowDialogActivity;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import org.json.JSONObject;

public class ezr {
    private static ezr ॱ;
    private String ˊ;
    private HashMap<String, GameInfo> ˎ = new HashMap();

    static class c extends Handler {
        c(Looper looper) {
            super(looper);
        }
    }

    private ezr() {
    }

    public static synchronized ezr ˎ() {
        ezr o_ezr;
        synchronized (ezr.class) {
            if (ॱ == null) {
                ॱ = new ezr();
            }
            o_ezr = ॱ;
        }
        return o_ezr;
    }

    private void ˋ(GameInfo gameInfo) {
        this.ˎ.put(gameInfo.getAppId(), gameInfo);
    }

    private GameInfo ˎ(String str) {
        return (GameInfo) this.ˎ.get(str);
    }

    void ˎ(fad o_fad, GetGameNoticeResp getGameNoticeResp) {
        String str = null;
        if (getGameNoticeResp != null) {
            try {
                JSONObject jSONObject = new JSONObject(getGameNoticeResp.toJson());
                if (getGameNoticeResp.getResponseCode() != 0) {
                    jSONObject.put("responseCode", getGameNoticeResp.getResponseCode());
                }
                jSONObject.remove("noticeMap");
                str = jSONObject.toString();
            } catch (Exception e) {
                Logger.e("GameNoticeInfoManager", "String to Json exception");
            }
        }
        try {
            if (this.ˊ != null) {
                o_fad.ˋ(this.ˊ, str);
            }
        } catch (RemoteException e2) {
            Logger.e("GameNoticeInfoManager", "callback response exception");
        }
    }

    private boolean ˎ(Context context, GameInfo gameInfo, String str) {
        if (dof.ˋ(str)) {
            return false;
        }
        try {
            return ˎ(new StringBuffer(context.getApplicationContext().getFilesDir().getAbsolutePath()).append(File.separator).append("gamebox").append(File.separator).toString(), gameInfo.getPackageName() + "NoticeFile.html", new String(dnk.ˎ(str), StandardCharsets.UTF_8));
        } catch (Exception e) {
            Logger.e("GameNoticeInfoManager", "UnsupportedEncodingException");
            return false;
        }
    }

    private boolean ˎ(String str, String str2, String str3) {
        Throwable th;
        Throwable th2;
        File file = new File(str);
        FileOutputStream fileOutputStream;
        if (file.exists() || file.mkdir()) {
            try {
                try {
                    fileOutputStream = new FileOutputStream(new File(str, str2));
                    th = null;
                    try {
                        fileOutputStream.write(str3.getBytes(StandardCharsets.UTF_8));
                        fileOutputStream.flush();
                        if (fileOutputStream != null) {
                            if (th != null) {
                                try {
                                    fileOutputStream.close();
                                } catch (Throwable th22) {
                                    th.addSuppressed(th22);
                                }
                            } else {
                                fileOutputStream.close();
                            }
                        }
                        return true;
                    } catch (Throwable th3) {
                        Throwable th4 = th3;
                        th3 = th22;
                        th22 = th4;
                    }
                } catch (IOException e) {
                    Logger.e("GameNoticeInfoManager", "Fail to writeFile");
                    return false;
                }
            } catch (Exception e2) {
                return false;
            }
        }
        Logger.e("GameNoticeInfoManager", "Fail to create path");
        return false;
        if (fileOutputStream != null) {
            if (th3 != null) {
                try {
                    fileOutputStream.close();
                } catch (Throwable th5) {
                    th3.addSuppressed(th5);
                }
            } else {
                fileOutputStream.close();
            }
        }
        throw th22;
        throw th22;
    }

    private String ˏ(Context context, String str) {
        return new StringBuffer(context.getApplicationContext().getFilesDir().getAbsolutePath()).append(File.separator).append("gamebox").append(File.separator).append(str).append("NoticeFile.html").toString();
    }

    public void ˏ(String str) {
        GameInfo ˎ = ˎ(str);
        if (ˎ != null) {
            dgh.ॱ(ContentManager.getInstant().getContext(), "15030112", new StringBuffer(KeyAndValue.NUMBER_01).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(UserSession.getInstance().getUserId()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(ˎ.getPackageName()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(str).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(ˎ.getSdkVersionCode()).toString());
        }
    }

    public void ॱ(String str) {
        GameInfo ˎ = ˎ(str);
        if (ˎ != null) {
            dgh.ॱ(ContentManager.getInstant().getContext(), "15030206", new StringBuffer().append(KeyAndValue.NUMBER_01).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(UserSession.getInstance().getUserId()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(ˎ.getPackageName()).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(str).append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR).append(ˎ.getSdkVersionCode()).toString());
        }
    }

    public void ˋ(String str) {
        this.ˊ = str;
    }

    public void ˊ(String str) {
        this.ˎ.remove(str);
    }

    void ॱ(Context context, GameInfo gameInfo, GetGameNoticeResp getGameNoticeResp, long j, long j2, fad o_fad) {
        if (new ezz(gameInfo, getGameNoticeResp, j, j2).ˊ() && ˎ(context, gameInfo, getGameNoticeResp.ˋ().ˎ())) {
            ˋ(gameInfo);
            final Intent intent = new Intent(ContentManager.getInstant().getContext(), GameServiceShowDialogActivity.class);
            intent.putExtra("appId", gameInfo.getAppId());
            intent.putExtra("noticeTitle", getGameNoticeResp.ˋ().ॱ());
            intent.putExtra("detailUrl", getGameNoticeResp.ˋ().ˋ());
            intent.putExtra("filePath", ˎ().ˏ(context, gameInfo.getPackageName()));
            intent.putExtra("dialogClass", far.class.getName());
            String ॱॱ = getGameNoticeResp.ˋ().ॱॱ();
            int i = 80;
            if (!dof.ˋ(ॱॱ)) {
                try {
                    i = Integer.parseInt(ॱॱ);
                } catch (Exception e) {
                    Logger.ˏ("GameNoticeInfoManager", "parseInt heightPercentString error");
                }
                if (i < 20 || i > 80) {
                    Logger.ˏ("GameNoticeInfoManager", "invalid heightPercent: " + i);
                    i = 80;
                }
            }
            intent.putExtra("heightPercent", i);
            final GameInfo gameInfo2 = gameInfo;
            final fad o_fad2 = o_fad;
            c anonymousClass4 = new c(this, Looper.getMainLooper()) {
                final /* synthetic */ ezr ˎ;

                public void handleMessage(Message message) {
                    fab.ˎ().ˏ(gameInfo2, intent, o_fad2);
                }
            };
            anonymousClass4.sendMessage(anonymousClass4.obtainMessage());
            if (Logger.ˎ()) {
                Logger.ˏ("GameNoticeInfoManager", "send show notice message");
            }
        }
    }
}
